const { defineConfig } = require('@vue/cli-service');

const path = require('path');
const defaultSettings = require('./src/settings.js');

function resolve(dir) {
    return path.join(__dirname, dir);
}

module.exports = defineConfig({
    transpileDependencies: true,
    lintOnSave: process.env.NODE_ENV === 'development',
    devServer: {
        client: {
            progress: true,
            logging: 'none',
            overlay: false,
        },
        // 设置代理
        proxy: {
            '/prod-api': {
                target: 'https://ht.aiaabiok.com/', // 域名
                ws: true, // 是否启用websockets
                changeOrigin: true, //开启代理：在本地会创建一个虚拟服务端，然后发送请求的数据，并同时接收请求的数据，这样服务端和服务端进行数据的交互就不会有跨域问题
                pathRewrite: {
                    '^/prod-api': '/prod-api',
                },
                headers: {
                    Referer: 'https://ht.aiaabiok.com/',
                },
            },
        },
    },
    
    configureWebpack: {
        devtool: 'source-map',
        resolve: {
            alias: {
                '@': resolve('src'),
            },
            fallback: { path: require.resolve('path-browserify') },
        },
    },
    chainWebpack(config) {
        config.plugins.delete('prefetch');
        // set svg-sprite-loader
        config.module.rule('svg').exclude.add(resolve('src/icons')).end();
        config.module
            .rule('icons')
            .test(/\.svg$/)
            .include.add(resolve('src/icons'))
            .end()
            .use('svg-sprite-loader')
            .loader('svg-sprite-loader')
            .options({
                symbolId: 'icon-[name]',
            })
            .end();
    },
});
